package com.zhentao.product.controller;

import com.zhentao.nlz.project.dto.TFileManageDto;
import com.zhentao.nlz.project.product.TFileManage;
import com.zhentao.product.service.TFileManageService;
import com.zhentao.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("tFileManage")
public class TFileManageController {
    @Autowired
    private TFileManageService tFileManageService;


    @GetMapping("fileList")
    public Result fileList(){
        return tFileManageService.fileList();
    }
    //文件上传三要素： post请求   enctype=‘mutilpart/form-data’  参数和前端input的name属性一致
    @PostMapping("upload")
    public Result upload(@RequestParam("file") MultipartFile file){
        System.err.println("123"+file);
      /*  try {

            InputStream inputStream = file.getInputStream();
            String originalFilename = file.getOriginalFilename();
            System.out.println("文件名："+originalFilename);
            file.transferTo(new File("D:/"+originalFilename));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/
        String fileName = tFileManageService.upload(file);
        return Result.success(fileName);
    }
    @PostMapping("save")
    public Result save(TFileManage fileManage){
        return Result.success(tFileManageService.saveData(fileManage));
    }

    @GetMapping("delete")
    public Result delete(@RequestParam("id") Integer id){
        return tFileManageService.delete(id);
    }
    @PostMapping("update")
    public Result update(TFileManage fileManage){
        System.err.println("fileManage:"+fileManage);
        return tFileManageService.updateDataById(fileManage);
    }
}
